package org.wevil.util;

import java.util.ArrayList;
import java.util.List;

/**
 * fel引擎解析公式参数
 *
 * @author wanglei
 * @since 2021/6/1
 * */
public class FelUtil {

    final private static String[] symbols = new String[]{
            "+", "-", "*", "/", "(", ")", ">", "<", "=",
    };

    /**
     * fel引擎解析公式参数，返回公式里的参数信息
     *
     * @author wanglei
     * @since 2021/6/1
     * */
    public static List<String> parseFormula(String formula){
        List<String> params = new ArrayList<>();
        for(String symbol : symbols){
            formula = formula.replace(symbol, "#");
        }
        if(formula.contains("#")){
            String[] split = formula.split("#");
            for(String s : split){
                if(!NumberUtil.isNumeric(s)){
                    params.add(s);
                }
            }
        }
        params = ListUtil.removeDuplicateWithOrder(params);
        return params;
    }
}
